window.onload = function(){
var prev = document.getElementById("prev");
var next = document.getElementById("next");
var img = document.getElementsByTagName("img")[0];

//创建一个数组，用来保存图片路径
var imgArr = ["img/1.jpg","img/2.jpg","img/3.jpg","img/4.jpg","img/5.jpg"];
var index = 0;
var info = document.getElementById("info");
info.innerHTML = "一共有"+imgArr.length+",现在是第"+ (index+1) +"张图片";
console.log(index);

prev.onclick = function(){
    if(index<=0){
        index = imgArr.length-1;
    }
    else{
        index--;
    }
    //index--;
    img.src = imgArr[index];
 //   console.log(img.src);
 info.innerHTML = "一共有"+imgArr.length+",现在是第"+ (index+1) +"张图片";
 
}

next.onclick = function(){
    if(index>=imgArr.length-1){
        index = 0;
    }
    else {
        index++;
    }
    img.src = imgArr[index];
 //   console.log(img.src);
 info.innerHTML = "一共有"+imgArr.length+",现在是第"+ (index+1) +"张图片";
}


}